# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=graphicsmagick
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.25
pkgrel=1
pkgdesc="An image viewing/manipulation program (mingw-w64)"
arch=('any')
url="http://www.graphicsmagick.org/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-ghostscript"
             "${MINGW_PACKAGE_PREFIX}-jasper"
             "${MINGW_PACKAGE_PREFIX}-libpng"
             "${MINGW_PACKAGE_PREFIX}-libtiff"
             "${MINGW_PACKAGE_PREFIX}-libxml2"
             "${MINGW_PACKAGE_PREFIX}-libwebp"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-jbigkit"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libtool"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib")
         #"${MINGW_PACKAGE_PREFIX}-perl"
optdepends=("${MINGW_PACKAGE_PREFIX}-ghostscript: for Ghostscript support"
            "${MINGW_PACKAGE_PREFIX}-libxml2: for XML support"
            "${MINGW_PACKAGE_PREFIX}-jasper: for JPEG-2000 support"
            "${MINGW_PACKAGE_PREFIX}-libpng: for PNG support"
            "${MINGW_PACKAGE_PREFIX}-libtiff: for PNG support"
            "${MINGW_PACKAGE_PREFIX}-libwebp: for WEBP support")
options=('staticlibs' 'strip' 'libtool')
source=(https://sourceforge.net/projects/graphicsmagick/files/${_realname}/${pkgver}/GraphicsMagick-${pkgver}.tar.xz
        001-relocate.patch)
sha256sums=('d64bfa52d2e0730eff9ce3ed51d4fc78dbb68e2adaa317b2bb3c56e6ee61ac9f'
            'd960ba9ebb98acc922794315913e743938fb0b903aa3ab0652eb653e2641b232')

prepare() {
  cd GraphicsMagick-${pkgver}
  patch -p1 -i ${srcdir}/001-relocate.patch

  autoreconf -fiv
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd GraphicsMagick-${pkgver}
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  ../GraphicsMagick-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --disable-static \
    --with-modules \
    --with-wmf \
    --with-xml \
    --with-lcms2 \
    --with-jp2 \
    --with-webp \
    --with-gslib \
    --with-jbig \
    --without-fpx \
    --without-dps \
    --without-perl \
    --without-x

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
}
